package com.regent.central.bill.web.mrp.billReturn;

import com.regent.central.bill.repository.mrp.dto.billReturn.BillMaterialReturnPageDTO;
import com.regent.central.bill.repository.mrp.dto.billReturn.BillMaterialReturnPageParam;
import com.regent.central.bill.repository.mrp.dto.billReturn.BillReturnUndoResult;
import com.regent.central.bill.repository.mrp.dto.billReturn.collect.BillMaterialReturnCollectAddDTO;
import com.regent.central.bill.repository.mrp.dto.billReturn.create.BillMaterialReturnAddDTO;
import com.regent.central.bill.repository.mrp.dto.billReturn.detail.ReturnDetailsSkuDTO;
import com.regent.central.bill.service.mrp.BillMaterialReturnService;
import com.regent.central.bill.web.mrp.BillMaterialReturnDetailResponse;
import com.regent.central.bill.web.mrp.BillMaterialReturnExcelResponse;
import com.regent.central.bill.web.mrp.BillReturnUndoResponse;
import com.regent.central.infrastructure.web.BasicResponse;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: 退料单Controller
 * @Author: zhw
 * @company: 丽晶软件
 * @project: 巨牛云厂
 * @Date:Created in 2018/6/26
 */
@RestController
@RequestMapping(value = "/bill/material/return", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class BillMaterialReturnController {

    @Resource
    BillMaterialReturnService billMaterialReturnService;

    @PostMapping("/add")
    public BasicResponse create(@RequestBody BillMaterialReturnAddDTO returnAdd) {
        billMaterialReturnService.create(returnAdd);
        return new BasicResponse();
    }


    @GetMapping("/{billMaterialReturnId:\\w+}")
    public BillMaterialReturnDetailResponse detail(@PathVariable("billMaterialReturnId") String billMaterialReturnId) {
        BillMaterialReturnDetailResponse billMaterialReturnDetailResponse = new BillMaterialReturnDetailResponse();
        billMaterialReturnDetailResponse.setDetail(billMaterialReturnService.detail(billMaterialReturnId));
        return billMaterialReturnDetailResponse;
    }

    @PostMapping("/collect")
    public BasicResponse createCollectMoney(@RequestBody BillMaterialReturnCollectAddDTO collectAdd) {
        billMaterialReturnService.createCollectMoney(collectAdd);
        return new BasicResponse();
    }

    @DeleteMapping("/undo/{billMaterialReturnId:\\w+}")
    public BillReturnUndoResponse undo(@PathVariable("billMaterialReturnId") String billMaterialReturnId, @RequestParam("userId") String userId) {
        BillReturnUndoResponse response = new BillReturnUndoResponse();
        BillReturnUndoResult result = billMaterialReturnService.undo(billMaterialReturnId, userId);
        response.setResult(result);
        return response;
    }

    /**
     * 退料单分页查询列表
     */
    @PostMapping("/page")
    public BillMaterialReturnPageDTO findPage(@RequestBody BillMaterialReturnPageParam param){
        return billMaterialReturnService.findPage(param);
    }

    /**
     * 退料单分页查询列表
     */
    @PostMapping("/returnExcel")
    public BillMaterialReturnExcelResponse returnExcel(@RequestBody BillMaterialReturnPageParam param){
        BillMaterialReturnExcelResponse dto = new BillMaterialReturnExcelResponse();
        List<ReturnDetailsSkuDTO> returnDetailsSkuDTOS = billMaterialReturnService.returnExcel(param);
        dto.setList(returnDetailsSkuDTOS);
        return dto;
    }

}
